package com.makingTeam.server.service.impl;

import com.makingTeam.config.cache.CacheKeyGenerator;
import com.makingTeam.config.cache.LevelCache;
import com.makingTeam.server.mapper.Goods1Mapper;
import com.makingTeam.server.pojo.Goods1;
import com.makingTeam.server.service.Goods1Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author pzy
 * @since 2022-08-03
 */
@Service
@Slf4j
public class Goods1ServiceImpl extends ServiceImpl<Goods1Mapper, Goods1> implements Goods1Service {


    @Override
    @Cacheable(cacheNames = CacheKeyGenerator.USER_CACHE+"#10",
            key= "T(com.makingTeam.config.cache.CacheKeyGenerator).generateKey(#name)")
    public Object login(String name, String pwd) {
        Map<Object, Object> objectObjectMap = new HashMap<>();
        objectObjectMap.put(name, pwd);
        log.info("login-----查找数据库");
        return objectObjectMap;
    }

    @Override
    @CachePut(cacheNames = CacheKeyGenerator.USER_CACHE+"#30",
            key= "T(com.makingTeam.config.cache.CacheKeyGenerator).generateKey(#name)")
    public Object updateLogin(String name, String pwd) {
        Map<Object, Object> objectObjectMap = new HashMap<>();
        objectObjectMap.put(name, pwd);
        log.info("updateLogin----查找数据库");
        return objectObjectMap;
    }

    @CacheEvict(cacheNames = CacheKeyGenerator.USER_CACHE,
            key= "T(com.makingTeam.config.cache.CacheKeyGenerator).generateKey(#name)")
    @Override
    public void del(String name) {
        log.info("del----删除");
    }
}
